const supportDomainSuffixes = ['com.cn', 'net.cn', 'gov.cn', 'com', 'net', 'org', 'gov', 'cn', 'io', 'tech']

export const getDomain = (host: string = location.host): string => {
  host = host.split(':')[0]
  for (let suffix of supportDomainSuffixes) {
    suffix = '.' + suffix
    if (host.endsWith(suffix)) {
      const domain = host.substring(0, host.length - suffix.length)
      if (domain.includes('.')) {
        const arr = domain.split('.')
        return arr[arr.length - 1] + suffix
      } else {
        return domain + suffix
      }
    }
  }
  return host
}

export const setDocumentTitle = (title: any): void => {
  if (title) {
    document.title = title
  }
}
